package com.example.lenovo.demo.presenter;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.lenovo.demo.CityFirstActivity;
import com.example.lenovo.demo.MainActivity;
import com.example.lenovo.demo.model.Model;
import com.example.lenovo.demo.model.databean.CityHotBean;
import com.example.lenovo.demo.model.idatabean.IModel;
import com.example.lenovo.demo.model.idatabean.OnCityHotSuccess;
import com.example.lenovo.demo.presenter.adapter.CityHot_LvAdapter;
import com.example.lenovo.demo.view.ifgview.ICityHotFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/1/11.
 */

public class CityHotFgPresenter implements AdapterView.OnItemClickListener{
    private ICityHotFragment iCityHotFragment;
    private IModel iModel;
    private List<CityHotBean.DataBean> data;
    private CityHot_LvAdapter adapter;
    private ListView listView;
    private Context context;

    public CityHotFgPresenter(ICityHotFragment iCityHotFragment) {
        this.iCityHotFragment = iCityHotFragment;
        this.iModel=new Model();
        this.listView= iCityHotFragment.getLv();
    }
    public void initData(){
        context=iCityHotFragment.getCityHotContext();
        data=new ArrayList<>();
        adapter=new CityHot_LvAdapter(data,iCityHotFragment.getCityHotContext());
        iCityHotFragment.getProgressDialog().show();

        iModel.sendCityHotBean(iCityHotFragment.getArea(), new OnCityHotSuccess() {
            @Override
            public void CityHotSuccess(CityHotBean cityHotBean) {
                data.addAll(cityHotBean.getData());
                listView.setAdapter(adapter);
                MainActivity.drawerLayout.openDrawer(Gravity.RIGHT);
                MainActivity.drawerLayout.setVisibility(View.VISIBLE);
                iCityHotFragment.getProgressDialog().dismiss();
            }

            @Override
            public void CityHotFailed() {

            }
        });
        listView.setOnItemClickListener(this);


    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent=new Intent(context, CityFirstActivity.class);
        intent.putExtra("msg",data.get(i).getId()+"");
        context.startActivity(intent);

    }
}
